<?php
include 'seguranca.php';
require_once 'Model/DAO/ConnectionPDO.php';
require_once 'Model/Filiacao.php';
require_once 'Model/DAO/FiliacaoDAO.php';

// Valida sessao do usuario
protegePagina();

if(isset($_POST) && !empty($_POST))
{
   $nomePai = addslashes($_POST['pai']);
   $nomeMae = addslashes($_POST['mae']);

   $filiacao = new Filiacao();
   $filiacao->setNomePai($nomePai);
   $filiacao->setNomeMae($nomeMae);

   $filiacaoDAO = new FiliacaoDAO();
   $filiacaoDAO->addFiliacao($filiacao);

   if ($filiacaoDAO) {
     $msg = 'Filiação cadastrada com sucesso';
     header('Location: filiacao_cad.php?pag=1');
   }
   else {
     $msg =  'Ocorreu um erro tente novamente';
     header('Location: filiacao_cad.php');
   }
}
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='pt-br' lang='pt-br'>
    <head>
        <meta http-equiv='content-type' content='text/html; charset=utf-8' />
        <meta http-equiv='content-language' content='pt-br' />
        <meta name='robots' content='noindex,nofollow' />
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/reset.css' /> 
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/main.css' /> 
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/2col.css' title='2col' />
        <link rel='alternate stylesheet' media='screen,projection' type='text/css' href='css/1col.css' title='1col' />
        <!--[if lte IE 6]><link rel='stylesheet' media='screen,projection' type='text/css' href='css/main-ie6.css' /><![endif]--> <!-- MSIE6 -->
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/style.css' /> 
        <link rel='stylesheet' media='screen,projection' type='text/css' href='css/mystyle.css' /> 
        <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
        <script type='text/javascript' src='http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js'></script>
        <script type='text/javascript' src='js/maskedinput.js'></script>
        <script type='text/javascript' src='js/jquery.switcher.js'></script>
        <script type='text/javascript' src='js/toggle.js'></script>
        <script type='text/javascript'>
            $(document).ready(function(){
                $('#frmFili').validate({
                    // Reporta os erros no container
                    errorLabelContainer: '#error',
                    wrapper: 'li',
                    errorClass: 'campo-invalido',
                    rules: {
                      pai: {
                          required: true,
                          minlength: 3
                      },
                      mae: { required: true,minlength: 3}
                    },
                    messages: {
                       pai:{
                         required: 'Informe o <strong>NOME DO PAI</strong>',
                         minlength:'O <strong>NOME DO PAI</strong> deve ser maior que 3 caracteres'
                      },
                      mae: {
                         required: 'Informe o <strong>NOME DA MÃE</strong>',
                         minlength:'O <strong>NOME DA MÃE</strong> deve ser maior que 3 caracteres'
                      }
                    }
                });
            });
        </script>
        <title>Filiação</title>
    </head>
    <body>
        <div id='main'>
            <?php include 'includes/inc_header.php' ?>
            <?php include 'includes/inc_menu.php' ?>
            <div id='cols' class='box'><?php include 'includes/left-colum-cad.php' ?></div>

            <div id='content' class='box'>
                <h1>Cadastro de filiação</h1>
                <p class='msg info' id='resposta'><?=@$msg;?></p>
                <div class='msg error' id='error'></div>
                <form action='' method='post' id='frmFili'>
                    <fieldset>
                        <legend>Filiação</legend>
                        <p class='nomt'>
                            <label for='pai' class='req'>Touro: *</label><br />
                            <input type='text'
                                   size='60'
                                   name='pai'
                                   class='input-text required'
                                   id='pai'
                                   title="Preencha o nome do animal"  />
                        </p>

                        <p class='nomt'>
                            <label for='mae' class='req'>Matriz: *</label><br />
                            <input type='text'
                                   size='60'
                                   name='mae'
                                   class='input-text required'
                                   id='mae' />
                        </p>
                        <p><input type='submit' id="enviaFiliacao" value='Cadastrar Filiação' /></p>
                    </fieldset>
                </form>
            </div>
        </div>
        <hr class='noscreen' />
        <?php include 'includes/inc_footer.php' ?>
